//
//  SuperManTableViewCell.m
//  ThePrivateKitchen
//
//  Created by lirui on 16/1/23.
//  Copyright © 2016年 www.lanou3g.com蓝鸥科技. All rights reserved.
//

#import "SuperManTableViewCell.h"
#import "Frame.h"
#import "MaterialCollectionViewCell.h"
#import <UIImageView+WebCache.h>
@interface SuperManTableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property(nonatomic ,retain)UICollectionView *collectionView;
@end
@implementation SuperManTableViewCell

- (void)dealloc
{
    [_head release];
    [_nick release];
      [_content release];
    [super dealloc];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if ( self) {
        self.head = [[ UIImageView alloc] init];
      //  _head .backgroundColor= [ UIColor yellowColor];
        [self.contentView addSubview:_head];
        _head.layer.cornerRadius = 50 /2;
        _head.clipsToBounds = YES;
        [_head release];
        self.nick = [[UILabel alloc] init];
       // _nick.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_nick];
        self.content = [[ UILabel alloc] init];
       // _content.backgroundColor = [UIColor greenColor];
        [self.contentView addSubview:_content];
        [_content release];
        _content.font = [ UIFont systemFontOfSize:13];
        [self creatcollection];
      //  [_collectionView reloadData];
        
    }
    return  self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    _head.frame = CGRectMake(WIDTH*10, HEIGHT*10, WIDTH*50, HEIGHT*50);
    _nick.frame = CGRectMake(70 * WIDTH, HEIGHT*10, WIDTH *300, HEIGHT*30);
    _content.frame = CGRectMake(70 * WIDTH,HEIGHT * 40, _nick.frame.size.width , HEIGHT*20);
}
-(void)setModel:(ShipuModel*)model
{
    if (_model != model) {
        
   
    [_model release];
    _model= [model retain];
        
    }
    [self creatcollection];
    
}
-(void)creatcollection
{ UICollectionViewFlowLayout  *layout = [[ UICollectionViewFlowLayout alloc] init];
    //布局设置
    //滚动方向
    layout.scrollDirection =  UICollectionViewScrollDirectionHorizontal;
    //cell大小
    layout.itemSize = CGSizeMake(WIDTH*375 /3 ,100 *HEIGHT);
    //行列间距
    //行
    layout.minimumLineSpacing = 1 *WIDTH;
    //列
    layout.minimumInteritemSpacing = 0;
    //边界
    layout.sectionInset = UIEdgeInsetsMake(0,10 *HEIGHT,0,0);
    self.collectionView =[[ UICollectionView alloc] initWithFrame:CGRectMake(0  , WIDTH*60, WIDTH*375, HEIGHT*120)collectionViewLayout:layout];
    _collectionView .delegate = self;
    _collectionView.dataSource = self;
    _collectionView.backgroundColor = [UIColor whiteColor];
    _collectionView.showsHorizontalScrollIndicator = NO;
    [_collectionView release];
    _collectionView.pagingEnabled = NO;
    [_collectionView registerClass:[MaterialCollectionViewCell  class] forCellWithReuseIdentifier:@"cell"];
    [self.contentView addSubview:_collectionView];

}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section

{
    return _model.imageArr.count;
   }
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
   MaterialCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
        [cell.img sd_setImageWithURL:[NSURL URLWithString:_model.imageArr[indexPath.item]]];
   
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    /**调用协议方法*/
    [self.delegate clickCell:_textModel.textArr[indexPath.item]];
}
@end
